﻿using System;
using System.Data;
using System.Data.Common;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;

namespace Besture.UI.Admin.CommonModel.AutoMatic
{
    public partial class USER_tbhehuorenSet : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {

        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id <= 0)
            {
                return;
            }
            DataTable table = QueryDac.GetTable("SELECT * FROM tbhehuoren  WHERE ID = " + id);
            if (table.Rows.Count == 0)
                return;
            DataRow row = table.Rows[0];
			Name.Text = row["Name"].ToString();
            // name.Text = row["name"].ToString();
            // email.Text = row["email"].ToString();
            // jointime.Text = DateTime.Parse(row["jointime"].ToString()).ToString("yyyy-MM-dd");
            // detail.Text = row["teamclass"].ToString();
        }
        #endregion

        #region 保存

        protected void btnSubmit_Click(object sender, EventArgs eventArgs)
        {
            int identityId = -1;
            //添加
            if (!EditPage)
            {
                BaseDataAccess baseDataAccess = new BaseDataAccess();

                string insertSql =
                        @"INSERT INTO tbhehuoren
                        (
                        	Name
	                       
                        )
                        VALUES
                        (
                        	@Name
	                        
                        )";

                try
                {
                    baseDataAccess.CreateConnection();
                    DbCommand ldcDBCommand = baseDataAccess.GetCommand(insertSql);
                    
                    baseDataAccess.SetParameter(ldcDBCommand, "@Name", DbType.String, Name.Text);
                    
                    
                    identityId = baseDataAccess.ExecuteNonQuery(ldcDBCommand);
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    baseDataAccess.CloseConnection();
                }


            }
            //编辑
            else
            {
                BaseDataAccess baseDataAccess = new BaseDataAccess();
                string updateSql =
                       @"UPDATE tbhehuoren
                        SET
							Name = @Name
	                        
	                    WHERE id = @id    
	                    ";
						
                try
                {
                    baseDataAccess.CreateConnection();
                    DbCommand ldcDBCommand = baseDataAccess.GetCommand(updateSql);
                    baseDataAccess.SetParameter(ldcDBCommand, "@Name", DbType.String, Name.Text);
                    baseDataAccess.SetParameter(ldcDBCommand, "@id", DbType.Int32, ID);
                    identityId = baseDataAccess.ExecuteNonQuery(ldcDBCommand);
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    baseDataAccess.CloseConnection();
                }
            }
            if (identityId > 0)
            {
                FunHelper.Alert("保存成功", "USER_tbhehuorenList.aspx");
            }
        }
        #endregion

        #region 取消

        public void btnCanel_Click(object sender, EventArgs eventArgs)
        {
        
        }

        #endregion
    }
}